import time

import action as action
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("http://121.43.169.97:8848/pageA.html")

"""打开注册页面A，在用户名文本框上点击鼠标右键"""
# action = ActionChains(driver)
# # 定位用户名输入框
# username = driver.find_element(By.CSS_SELECTOR, "#userA")
# # 调用鼠标右击
# d = action.context_click(username)
# # 执行
# d.perform()


"""打开注册页面A，输入用户名admin，暂停3秒钟后，双击鼠标左键，选中admin"""
action = ActionChains(driver)
username1 = driver.find_element(By.ID, "userA")
username1.send_keys("admin")
time.sleep(3)
action.double_click(username1).perform()


"""
打开‘drag.html’页面，把红色方框拖拽到蓝色方框上
"""
# url = r"D:\PythonProjects\UI自动化测试\01\drag.html"
# driver.get(url)
# action = ActionChains(driver)
# source = driver.find_element(By.CSS_SELECTOR, "#div1")
# target = driver.find_element(By.CSS_SELECTOR, "#div2")
# action.drag_and_drop(source, target).perform()


"""
打开注册页面A，模拟鼠标悬停在‘注册’按钮上
"""
# action = ActionChains(driver)
# button = driver.find_element(by=By.CSS_SELECTOR, value="button")
# action.move_to_element(button).perform()
